package com.iss.demo.controller;

import com.iss.demo.entity.Book;
import com.iss.demo.model.MyResponseData;
import com.iss.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("book/")
public class BookController {

    @Autowired
    private BookService service;

    @RequestMapping("selectAll")
    public List<Book> selectAll(){
        List<Book> list=service.selectAll();
        return list;
    }

    @RequestMapping("selectById")
    public List<Book> selectById(Integer u_id){
        List<Book> list=service.selectById(u_id);
        return list;
    }

    @RequestMapping("insertBook")
    public MyResponseData insertBook(Book book){
        service.insertBook(book);
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("预约成功");
        return responseData;
    }


    @RequestMapping("deleteOne")
    public MyResponseData delete(Integer b_id){
        service.deleteOne(b_id);
        MyResponseData responseData = new MyResponseData();
        responseData.setErrorCode(0);
        responseData.setStatus("预约成功");
        return responseData;
    }

    @RequestMapping("update")
    public MyResponseData update(Integer b_id){
        service.updateBook(b_id);
        MyResponseData responseData=new MyResponseData();
        responseData.setStatus("确认成功");
        responseData.setErrorCode(0);
        return responseData;
    }

}
